class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        //创建哑结点
        ListNode newListNode = new ListNode(-1); 
        ListNode tmp = newListNode;
        while(l1 != null && l2 != null){
            //谁小把谁放在前面
            if(l1.val <= l2.val){
                tmp.next = l1;
                l1 = l1.next;
            }else{
                tmp.next = l2;
                l2 = l2.next;
            }
            tmp = tmp.next;
        }
        //当循环退出时，说明有一个链表已经为空，将另外一个链表直接挂在后面
        if(l1 == null){
            tmp.next = l2;
        }else{
            tmp.next = l1;
        }
        return newListNode.next;
    }
}